package cn.sh.yhk.mapper.basic;

import cn.sh.yhk.model.basic.SUser;
import cn.sh.yhk.model.basic.SUserExample;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import javax.jdo.annotations.Cacheable;
import java.util.List;

@Mapper
public interface SUserMapper {
    @SelectProvider(type = SUserSqlProvider.class, method = "countByExample")
    long countByExample(SUserExample example);

    @DeleteProvider(type = SUserSqlProvider.class, method = "deleteByExample")
    int deleteByExample(SUserExample example);

    @Insert({
            "insert into s_user (user_id, user_account, ",
            "password, ",
            "user_name, user_search_name, ",
            "mobile_number, time_zone, ",
            "sex, id_card_cd, country_cd, ",
            "zip_code, address1, ",
            "address2, address3, ",
            "telephone_number, remark, ",
            "activity, locked, ",
            "reset_password, sort_key, ",
            "create_account, modify_account, ",
            "create_timestamp, modify_timestamp, ",
            "last_login_timestamp,email)",
            "values (#{userId,jdbcType=BIGINT}, #{userAccount,jdbcType=VARCHAR}, ",
            "#{password,jdbcType=VARCHAR}, ",
            "#{userName,jdbcType=VARCHAR}, #{userSearchName,jdbcType=VARCHAR}, ",
            "#{mobileNumber,jdbcType=VARCHAR}, #{timeZone,jdbcType=VARCHAR}, ",
            "#{sex,jdbcType=VARCHAR}, #{idCardCd,jdbcType=VARCHAR}, #{countryCd,jdbcType=VARCHAR}, ",
            "#{zipCode,jdbcType=VARCHAR}, #{address1,jdbcType=VARCHAR}, ",
            "#{address2,jdbcType=VARCHAR}, #{address3,jdbcType=VARCHAR}, ",
            "#{telephoneNumber,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, ",
            "#{activity,jdbcType=VARCHAR}, #{locked,jdbcType=INTEGER}, ",
            "#{resetPassword,jdbcType=INTEGER}, #{sortKey,jdbcType=BIGINT}, ",
            "#{createAccount,jdbcType=VARCHAR}, #{modifyAccount,jdbcType=VARCHAR}, ",
            "#{createTimestamp,jdbcType=TIMESTAMP}, #{modifyTimestamp,jdbcType=TIMESTAMP}, ",
            "#{lastLoginTimestamp,jdbcType=TIMESTAMP},#{email,jdbcType=VARCHAR})"
    })
    int insert(SUser record);

    @InsertProvider(type = SUserSqlProvider.class, method = "insertSelective")
    int insertSelective(SUser record);

    @SelectProvider(type = SUserSqlProvider.class, method = "selectByExample")
    @Results({
            @Result(column = "user_id", property = "userId", jdbcType = JdbcType.BIGINT),
            @Result(column = "user_account", property = "userAccount", jdbcType = JdbcType.VARCHAR),
            @Result(column = "password", property = "password", jdbcType = JdbcType.VARCHAR),
            @Result(column = "user_name", property = "userName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "user_search_name", property = "userSearchName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "mobile_number", property = "mobileNumber", jdbcType = JdbcType.VARCHAR),
            @Result(column = "time_zone", property = "timeZone", jdbcType = JdbcType.VARCHAR),
            @Result(column = "sex", property = "sex", jdbcType = JdbcType.VARCHAR),
            @Result(column = "id_card_cd", property = "idCardCd", jdbcType = JdbcType.VARCHAR),
            @Result(column = "country_cd", property = "countryCd", jdbcType = JdbcType.VARCHAR),
            @Result(column = "zip_code", property = "zipCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "address1", property = "address1", jdbcType = JdbcType.VARCHAR),
            @Result(column = "address2", property = "address2", jdbcType = JdbcType.VARCHAR),
            @Result(column = "address3", property = "address3", jdbcType = JdbcType.VARCHAR),
            @Result(column = "telephone_number", property = "telephoneNumber", jdbcType = JdbcType.VARCHAR),
            @Result(column = "remark", property = "remark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "activity", property = "activity", jdbcType = JdbcType.VARCHAR),
            @Result(column = "locked", property = "locked", jdbcType = JdbcType.INTEGER),
            @Result(column = "reset_password", property = "resetPassword", jdbcType = JdbcType.INTEGER),
            @Result(column = "sort_key", property = "sortKey", jdbcType = JdbcType.BIGINT),
            @Result(column = "create_account", property = "createAccount", jdbcType = JdbcType.VARCHAR),
            @Result(column = "modify_account", property = "modifyAccount", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_timestamp", property = "createTimestamp", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_timestamp", property = "modifyTimestamp", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "last_login_timestamp", property = "lastLoginTimestamp", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "session_id", property = "sessionId", jdbcType = JdbcType.VARCHAR),
    })
    List<SUser> selectByExample(SUserExample example);

    @UpdateProvider(type = SUserSqlProvider.class, method = "updateByExampleSelective")
    int updateByExampleSelective(@Param("record") SUser record, @Param("example") SUserExample example);

    @UpdateProvider(type = SUserSqlProvider.class, method = "updateByExample")
    int updateByExample(@Param("record") SUser record, @Param("example") SUserExample example);

    @Insert("insert into s_user_group (user_id,group_id) values (#{userId},#{groupId})")
    int insertUserGroup(@Param("userId") Long userId, @Param("groupId") Long groupId);

    @Delete("delete from s_user_group where user_id=#{userId}")
    int deleteUserGroup(@Param("userId") Long userId);

    @Insert("insert into s_user_menu (user_id,menu_id) values (#{userId},#{menuId})")
    int insertUserMenu(@Param("userId") Long userId, @Param("menuId") Long menuId);

    @Delete("delete from s_user_menu where user_id=#{userId}")
    int deleteUserMenu(@Param("userId") Long userId);
}